<template>
  <div class="userCheckList">
    <h3>用户查单</h3>
    <div class="search">
      <div class="cond1 cond">
        <el-input placeholder="请输入订单号" v-model="search1">
          <template slot="prepend">订单号</template>
        </el-input>
      </div>
      <div class="cond1 cond">
        <el-input placeholder="请输入用户姓名" v-model="search2">
          <template slot="prepend">用户名</template>
        </el-input>
      </div>
      <div class="cond1 cond">
        <el-input placeholder="请输入用户ID" v-model="search3">
          <template slot="prepend">用户ID</template>
        </el-input>
      </div>
      <div class="cond2 cond">
        <label>查单状态</label>
        <el-select v-model="search4" placeholder="请选择">
          <el-option
            v-for="item in optionsCheckList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </div>
      <div>
        <el-button type="primary" icon="el-icon-search" @click="searchMethod">搜索</el-button>
      </div>
    </div>
    <div class="list">
      <el-table
        border
        ref="multipleTable"
        :data="tableData"
        tooltip-effect="dark"
        style="width: 100%"
      >
        <el-table-column type="index" width="50" header-align="center" align="center" label="序号"></el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          prop="order_sn"
          label="订单号"
          sortable
          width="190"
        ></el-table-column>
        <el-table-column header-align="center" align="center" prop="nick" label="用户名" width="80"></el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          prop="user_id"
          label="用户ID"
          width="80"
        ></el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          prop="device_text"
          label="设备"
          width="60"
        ></el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          prop="vip_title"
          label="购买内容"
          width="80"
        ></el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          prop="order_amount"
          label="订单金额"
          width="80"
        ></el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          prop="real_amount"
          label="支付金额"
          width="80"
        ></el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          prop="status_text"
          label="状态"
          width="80"
        ></el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          prop="pay_type"
          label="支付方式"
          width="80"
        ></el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          prop="pay_gate_way"
          label="支付通道"
          width="80"
        ></el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          prop="created_at"
          label="创建时间"
          width="100"
        ></el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          prop="pay_time"
          label="支付时间"
          width="100"
        ></el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          prop="admin_action_at"
          label="查单日期"
          sortable
          width="100"
        ></el-table-column>
        <el-table-column header-align="center" align="center" label="支付凭证" >
          <template slot-scope="scope">
            <el-image
              style="width: 100px; height: 100px"
              :src="item"
              :preview-src-list="scope.row.payproof_imgs_list"
              v-for="(item,index) in scope.row.payproof_imgs_list"
              :key="index"
            ></el-image>
          </template>
        </el-table-column>
        <el-table-column header-align="center" align="center" label="操作" width="90" fixed="right">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="warning"
              @click="handleCheckList(scope.$index, scope.row)"
              v-if="scope.row.is_admin_action==0"
            >未查单</el-button>
            <el-button size="mini" type="success" v-if="scope.row.is_admin_action==1">已查单</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="page">
     <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="currentPage1"
        :page-sizes="[10,30,50,100]"
        :page-size="pageSize"
        layout="total, prev, pager, next,sizes,jumper"
        :total="totalSize"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
//
export default {
  name: "userCheckList",
  data() {
    return {
      optionsCheckList: [
        {
          value: "",
          label: "全部"
        },
        {
          value: 0,
          label: "未查单"
        },
        {
          value: 1,
          label: "已查单"
        }
      ],
      search1: "",
      search2: "",
      search3: "",
      search4: "",
      tableData: [],
      currentPage1: 1,
      pageSize: 10,
      totalSize: 0,
      checkList: [],
      initData: {},
      // 权限管理
      permissions: [],
      permissions_obj: {}
    };
  },
  created() {
    //权限判断
    this.permissions = this.$store.state.permissions;
    let oneOff = false;
    this.permissions.forEach((item, index) => {
      if (item == -1) {
        oneOff = true;
      } else {
        this.permissions_obj["id_" + item] = item;
      }
    });
    if (oneOff) {
      this.permissions_obj.id_all = true;
    } else {
      this.permissions_obj.id_all = false;
    }
  },
  mounted() {
    this.getInitList();
  },
  methods: {
    searchMethod() {
      this.currentPage1 = 1;
      this.getInitList();
    },
    // 分页
    handleCurrentChange(val) {
      this.currentPage1 = val;
      this.getInitList();
    },
     handleSizeChange(val){
      this.pageSize=val;
      this.getInitList();
    },
    //获取初始化列表
    async getInitList() {
      let parames = {
        handshake: "",
        data: {
          page: this.currentPage1,
          page_size: this.pageSize,
          search: {
            order_sn: this.search1,
            nick: this.search2,
            user_id: this.search3,
            is_admin_action: this.search4
          }
        }
      };
      let res = await this.$axios.post(
        this.$api.orderUser_order_list,
        JSON.stringify(parames)
      );
      if (res.code == 200) {
        this.initData = res.data;
        this.initData.data.forEach((item, index) => {
          if (item.device_type == "I") {
            item.device_text = "苹果";
          } else if (item.device_type == "A") {
            item.device_text = "安卓";
          } else if (item.device_type == "H") {
            item.device_text = "来源h5";
          }
          if (item.status == 0) {
            item.status_text = "待支付";
            item.status_booln = false;
          } else if (item.status == 1) {
            item.status_text = "已支付";
            item.status_booln = true;
          } else if (item.status == 2) {
            item.status_text = "已取消";
          }
        });
        this.totalSize = this.initData.total;
        this.tableData = this.initData.data;
      } else {
        this.$message({
          message: res.message,
          type: "warning"
        });
      }
    },
    //查单
    handleCheckList(index, row) {
      if (!this.permissions_obj.id_48 && !this.permissions_obj.id_all) {
        this.$message({
          type: "info",
          message: "没有权限进行操作"
        });
        return;
      }
      this.$confirm("是否继续该操作?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.checkListMethod(row.order_sn);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消操作"
          });
        });
    },
    //查单接口
    async checkListMethod(order) {
      let parames = {
        handshake: "",
        data: {
          order_sn: order
        }
      };
      let res = await this.$axios.post(
        this.$api.orderSet_user_order,
        JSON.stringify(parames)
      );
      if (res.code == 200) {
        this.$message({
          message: res.message,
          type: "success"
        });
        this.getInitList();
      } else {
        this.$message({
          message: res.message,
          type: "warning"
        });
      }
    }
  }
};
</script>
<style scoped>
h3 {
  padding: 0.2rem;
  color: #3c763d;
}
.search {
  display: flex;
  margin-top: 0.2rem;
  padding-left: 0.2rem;
  width: 100%;
  flex-wrap: wrap;
}
.el-input {
  width: 2.5rem;
}
label {
  width: 0.83rem;
  height: 0.4rem;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #f5f7fa;
  color: #909399;
  border: 1px solid #dcdfe6;
  border-top-left-radius: 4px;
  border-bottom-left-radius: 4px;
  font-size: 14px;
}
.cond {
  display: flex;
  margin-right: 0.4rem;
  margin-bottom: 0.1rem;
}
.search .el-select >>> .el-input__inner {
  border-left: none;
  border-top-left-radius: 0px;
  border-bottom-left-radius: 0px;
}
.search .el-select {
  width: 1.67rem;
}
.opration {
  margin-top: 0.2rem;
  padding-left: 0.2rem;
}
.page {
  margin-top: 0.2rem;
  display: flex;
  justify-content: center;
}
.list {
  margin-top: 0.2rem;
  padding: 0 0.1rem;
  font-size: 0.12rem;
}
.list img {
  max-height: 0.4rem;
}
.el-image {
  max-height: 0.4rem;
  max-width: 40%;
  margin-right: 0.05rem;
}
</style>